<?php
/**
 * Created by PhpStorm.
 * User: apple
 * Date: 2020/10/12
 * Time: 4:06 PM
 */
namespace app\admin\logic;

use app\model\Organization;
use app\model\Token;
use app\model\User;
use think\facade\Request;

class QiniuLogic
{
    public function check()
    {
        $token = Request::header('token') ? Request::header('token') : Request::param('token');

        if(env('APP_ENV') == 'local'){
            $token = '73faaeb2a39c37a9c5a32db237622cfd';
        }
        if (!$token) {
            fail('请先登录系统',[],401);
        }

        $tokenModel = new Token();
        $uid = $tokenModel->verifyToken($token);

        $userModel = new User();
        $userInfo = $userModel->getUserInfoById($uid);
        config($userInfo,'user');
        return true;
    }

    /*
     * 获取用户信息
     */
    public function getAdminInfo()
    {
        $token = Request::header('token') ? Request::header('token') : Request::param('token');
        $tokenModel = new Token();
        $uid = $tokenModel->verifyToken($token);

        $userModel = new User();
        $userInfo = $userModel->getUserInfoById($uid,'id,pername,phone,position,orgid');
        if(!$userInfo)  fail('请重新登录',[],401);

        //组织信息
        $orgModel = new Organization();
        $userInfo['org'] = $orgModel->getOrgListByOrgId($userInfo['orgid']);

        return $userInfo;
    }
}